package com.dlc.felear.xiaoensale.helper;

import android.content.Context;
import android.util.Log;

import com.dlc.felear.xiaoensale.constant.Constant;
import com.dlc.felear.xiaoensale.constant.TempData;
import com.dlc.felear.xiaoensale.dao.ActionStepItemDao;
import com.dlc.felear.xiaoensale.dao.FlavourSpeedDao;
import com.dlc.felear.xiaoensale.dao.LocalUserDao;
import com.dlc.felear.xiaoensale.dao.SfPositionDao;
import com.dlc.felear.xiaoensale.entity.LocalUser;
import com.dlc.felear.xiaoensale.entity.SfPosition;
import com.dlc.felear.xiaoensale.utils.GetValueFromServer;
import com.dlc.felear.xiaoensale.utils.UuidUtil;

public class InitBaseData {
    private static final String TAG="InitBaseData";
    private Context context;
    private LoadDataHelper loadDataHelper;

    public InitBaseData(Context context) {
        try {
            this.context = context;
            loadDataHelper= LoadDataHelper.getInstance(context);
            loadDataHelper.setDisableDialog(false);
            GetValueFromServer.getInstance(context).updateInfo();
            initData();
        }catch (Exception e){
            Log.e(TAG,e.getMessage());
        }
    }
    private void initData(){
        loadDataHelper.initDtatByOsstart();
        ActionStepItemDao actionStepItemDao=new ActionStepItemDao(context);
        actionStepItemDao.addAll(TempData.getActionStepItemData());
        actionStepItemDao.addAll(TempData.getActionStepItemData1());
        actionStepItemDao.addAll(TempData.getActionStepItemData2());
        new FlavourSpeedDao(context).addAll(TempData.getFlavourDatas());
        new LocalUserDao(context).add(new LocalUser(UuidUtil.getUuidByName(Constant.USER_NAME),
                Constant.USER_NAME,"666888","zkyc321","admin"));
        initSfposion();
    }

    private void initSfposion(){
        SfPositionDao sfPositionDao=new SfPositionDao(context);
        SfPosition sfPosition1=sfPositionDao.queryForId(1);
        SfPosition sfPosition2=sfPositionDao.queryForId(2);
        //翻料盒伺服位置
        if(sfPosition1==null){
           SfPosition s1=new SfPosition();
            s1.setPosition1(0);
            s1.setPosition2(190000);
            s1.setPosition3(-90000);
            s1.setPosition4(0);
            s1.setPosition5(0);
            s1.setPosition6(0);
            s1.setPosition7(0);
            s1.setPosition8(0);
            s1.setPosition9(0);
            s1.setPosition10(0);
            s1.setPosition11(0);
            s1.setPosition12(0);
            s1.setPosition13(0);
            s1.setPosition14(0);
            s1.setPosition15(0);
            s1.setPosition16(0);
            sfPositionDao.add(s1);
        }
        //锅体伺服位置
        if(sfPosition2==null){
//            {-120000, -40000, 0, -70000, -60000, -55000, -12000, 0, 0}
           SfPosition s1=new SfPosition();
            s1.setPosition1(-120000);
            s1.setPosition2(-40000);
            s1.setPosition3(0);
            s1.setPosition4(-70000);
            s1.setPosition5(-60000);
            s1.setPosition6(-55000);
            s1.setPosition7(-12000);
            s1.setPosition8(0);
            s1.setPosition9(0);
            s1.setPosition10(0);
            s1.setPosition11(0);
            s1.setPosition12(0);
            s1.setPosition13(0);
            s1.setPosition14(0);
            s1.setPosition15(0);
            s1.setPosition16(0);
            sfPositionDao.add(s1);
        }
    }
}
